package patrol.mobile.com.mobilepatrol.activity.office;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;

import java.util.HashMap;

import butterknife.BindView;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.adapter.TabAdapter;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.ExaminationAllBean;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

public class ExaminationAllDetailActivity extends BaseActivity {

    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.tv2)
    TextView tv2;
    @BindView(R.id.tv3)
    TextView tv3;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private String date;
    private String orgId;
    private TabAdapter tabAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_examination_all_detail;
    }

    @Override
    public void initTitle() {
        super.initTitle();
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        CommonUtil.exitActivityAndBackAnim(ExaminationAllDetailActivity.this, true);
                    }
                });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("岗位考核记录明细");
        ExaminationAllBean data = (ExaminationAllBean) getIntent().getSerializableExtra("data");
        date = getIntent().getStringExtra("date");
        orgId = getIntent().getStringExtra("orgId");
        recyclerView.setLayoutManager(new LinearLayoutManager(ExaminationAllDetailActivity.this));
        tabAdapter = new TabAdapter(ExaminationAllDetailActivity.this);
        recyclerView.setAdapter(tabAdapter);
        requestData(data.getCheckId());
    }

    private void requestData(String id) {

        HttpSender sender = new HttpSender(this, baseUrl, Urls.GETORGPOSTTOTALENTITY);
        HashMap<String, String> map = new HashMap<>();
        map.put("orgId", orgId);
        map.put("month", date);
        map.put("checkId", id);
        sender.requestPost(map, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                Log.e("岗位考核记录明细", response);
                ExaminationAllBean examinationAllBean = new Gson().fromJson(response, ExaminationAllBean.class);
                tv1.setText(examinationAllBean.getCheckName());
                tv2.setText(examinationAllBean.getAssessor());
                tv3.setText(examinationAllBean.getTotalScore() + "分");
                tabAdapter.addItems(examinationAllBean.getOrgPostItemList());
            }
        });
    }

    @Override
    public void setListener() {

    }
}
